package ui.swing.scrolling;

import java.awt.Dimension;
import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.Scrollable;

public class ScrollableDemo extends JFrame {

	private static final long serialVersionUID = -6540641750952457618L;

	public ScrollableDemo() {
		super("JScrollPane Demo");
		ImageIcon ii = new ImageIcon(getClass().getResource("/resources/images/af.jpg"));
		JScrollPane jsp = new JScrollPane(new MyScrollableLabel(ii));
		getContentPane().add(jsp);
		setSize(300, 250);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	
	public static void main(String[] args) {
		new ScrollableDemo();
	}
	
}

class MyScrollableLabel extends JLabel implements Scrollable {

	private static final long serialVersionUID = 4068929951868503507L;

	public MyScrollableLabel(ImageIcon i) {
		super(i);
	}
	
	public Dimension getPreferredScrollableViewportSize() {
		return getPreferredSize();
	}

	public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
		return 10;
	}

	public boolean getScrollableTracksViewportHeight() {
		return false;
	}

	public boolean getScrollableTracksViewportWidth() {
		return false;
	}

	public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
		return 10;
	}
	
}